﻿using AppFramework.DinosaursParkMes.ProductionReturn.DTO;
using AppFramework.DinosaursParkMes.ProductionReturn;
using Models.DinosaursParkMes.ProductionReturn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ViewModels.DinosaursParkMes.ProductionReturn;
using DryIoc;
using System.IO;
using System.Data;
using HandyControl.Controls;
using Abp.Json;
using Newtonsoft.Json.Linq;

namespace AppFramework.Admin.HandyUI.Views.DinosaursParkMes.ProductionReturn
{
    /// <summary>
    /// ProductionReturnView.xaml 的交互逻辑
    /// </summary>
    public partial class ProductionReturnView : UserControl
    {
        private readonly IProductionReturninfoAppService appservice;
        public ProductionReturnView(IProductionReturninfoAppService appservice)
        {
            this.appservice = appservice;
            InitializeComponent();
            this.DataContext = new ProductionReturnViewModel(appservice);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int index = dataGrid.CurrentCell.Column.DisplayIndex;
            DataGridTemplateColumn templeColumn = dataGrid.Columns[index] as DataGridTemplateColumn;
            if (templeColumn == null) return;
            var item = dataGrid.CurrentCell.Item.ToJsonString();
            
            //var a= item.
            //FrameworkElement element = templeColumn.GetCellContent(item);
            //Expander expander = (Expander)templeColumn.CellTemplate.FindName("expander", element);
            //var selectedRow = dataGrid.SelectedItems as DataRow;
            //var id = selectedRow["id"].ToString();
            UptStatesId id = new UptStatesId();
            JObject jsonObj = JObject.Parse(item);
            //使用键名来取出相应的值
            id.Id = (int)jsonObj["Id"];
            appservice.UptStates(id);
            System.Windows.MessageBox.Show("退料成功");
            appservice.ProductionReturnList();
        }
    }
}
